import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

//静态路由配置
void main() => runApp(const MyApp3());

//定义根目录Widget
class MyApp3 extends StatelessWidget {
  const MyApp3({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      localizationsDelegates: const [
        //初始化默认的 Material 组件本地化
        GlobalMaterialLocalizations.delegate,
        //初始化默认的 通用 Widget 组件本地化
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      //当前区域，如果为null则使用系统区域一般用于语言切换
      //传入两个参数，语言代码，国家代码
      //这里配制为中国
      locale: const Locale('zh', 'CN'),
      //定义当前应用程序所支持的语言环境
      supportedLocales: const [
        Locale('en', 'US'), // English 英文
        Locale('zh', 'CN'), // 中文
      ],
      routes: {
        //默认页面
        "/": (BuildContext context) => const Exam304HomePage(),
      },
    );
  }
}

///代码清单 3-4 Stack 层叠布局
///代码路径 lib/code3/code304_Stack.dart
class Exam304HomePage extends StatelessWidget {
  const Exam304HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //页面的头部
      appBar: AppBar(title: const Text("标题")),
      body: Center(child: buildStack(),),
    );
  }
  ///代码清单 3-4 Stack 层叠布局
  ///代码路径 lib/code3/code304_Stack.dart
  buildStack() {
    return SizedBox(
      width: 40, height: 40,//限定大小
      child: Stack(
        alignment: Alignment.center,//子组合居中
        children: [
          Positioned(
            width: 33, height: 33,//设定子组件大小
            child: Image.asset(
              "assets/images/warning_icon.png",
            ),
          ),
          Positioned(
            top: 0,right: 0,//设定子组件右上角对齐
            child: ClipOval(//裁剪
              child: Container(
                width: 10, height: 10,
                color: Colors.red,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
